﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <style>
    </style>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>电源事业部</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">关键字</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="name" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">状态</label>
                                <div class="layui-input-inline">
                                    <select name="State" lay-search id="State">
                                        <option value="1" selected="selected">未完成</option>
                                        <option value="2">已完成</option>
                                        <option value="0">全部</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    {{#  if( @(Web.Common.Common.IsAuthoritys(20)) == 1){ }}
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                    @*<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>*@
                    {{#  } }}
                </div>
            </script>
            <table class="layui-hide" id="table" lay-filter="currentTableFilter"></table>
            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="details">添加工序</a>
                {{#  if( @(Web.Common.Common.IsAuthoritys(20)) == 1){ }}
                {{#  if(d.State==0){ }}
                <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-bg-cyan" lay-event="touchan">投产</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
                {{#  } }}
                {{#  if(d.State==1){ }}
                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="jiaofu">交付</a>
                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="wancheng">完成</a>
                {{#  } }}
                {{#  } }}
                <a class="layui-btn layui-btn-xs layui-btn-normal" href="/Bill5/Down?ID={{ d.ID }}">下载</a>

            </script>
        </div>
    </div>
    <script src="~/layui/layui.js"></script>
    <script src="~/layuimini/js/lay-config.js"></script>
    <script>
        layui.use(['form', 'table', 'miniTab'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                miniTab = layui.miniTab;

            table.render({
                elem: '#table',
                method: 'post',
                url: '@Url.Action("IndexListAsync", "Bill5")',
                request: {
                    pageName: 'PageIndex' //页码的参数名称，默认：page
                   , limitName: 'PageSize' //每页数据量的参数名，默认：limit
                },
                where: {
                    Search: $('#name').val(),
                    State: $('#State').val()
                },
                cellMinWidth: 120,
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print'],
                cols: [[
                    { type: "checkbox", width: 50 },
                    { type: 'numbers', title: '序号', width: 50 },
                    { field: 'ID', title: 'ID', width: 100, hide: true },
                    { field: 'Code', title: '流程卡号' },
                    { field: 'JinDu', title: '进度' },
                    { field: 'CreateDate', title: '投产日期' },
                    { field: 'GoodsModel', title: '产品型号' },
                    //{ field: 'GoodsCode', title: '产品编码' },
                    { field: 'GoodsNumber', title: '产品编号' },
                    //{ field: 'SourceGoodsCode', title: '芯片编码' },
                    { field: 'DanWei', title: '单位' },
                    { field: 'Number', title: '生产批号' },
                    { field: 'DengJi', title: '质量等级' },
                    { field: 'WaiXing', title: '封装外型' },
                    { field: 'Qty', title: '投产数量' },
                    { field: 'JiaoQty', title: '交付数量' },
                    { field: 'StateName', title: '状态' },
                    { fixed: 'right', title: '操作', toolbar: '#currentTableBar', width: 250 }
                ]],
                limits: [10, 20, 30, 50, 100, 100000000],
                limit: 20,
                page: true,
                //skin: 'line',
                //totalRow: true,
                height: 'full-170',
                size: 'sm',
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                //执行搜索重载
                RefreshTable();
                return false
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加流程卡',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: false,
                        area: ['1050px', '650px'],
                        content: '@Url.Action("IndexEdit", "Bill5")',
                        end: function () {
                            RefreshTable();

                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                } else if (obj.event === 'delete') {  // 监听删除操作
                    var checkStatus = table.checkStatus('table')
                        , data = checkStatus.data;
                    if (data.length == 0) {
                        layer.msg('请选择您要删除的数据！', { icon: 5, time: 2000 });
                        return;
                    }

                    var arr = [];
                    for (var i = 0; i < data.length; i++) {
                        arr.push(data[i].ID);
                    }

                    var ids = arr.join(",");


                    layer.confirm('您确定要删除所选数据吗', {
                        btn: ['是的', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            url: '@Url.Action("IndexDelAsync", "Bill5")',
                            type: "post",
                            dataType: "json",
                            data: { IDs: ids },
                            success: function (data) {
                                //Info,Success,Warning,Error
                                var type = data.Type;
                                if (type == 1) {
                                    layer.msg(data.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            RefreshTable();
                                        });
                                } else {
                                    layer.msg(data.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    }, function () {
                        return;
                    });
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {

                    var index = layer.open({
                        title: '修改流程卡',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: false,
                        area: ['1050px', '650px'],
                        content: '@Url.Action("IndexEdit", "Bill5")' + '?ID=' + data.ID,
                        end: function () {
                            RefreshTable();
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    layer.confirm('您确定要删除所选数据吗', {
                        btn: ['是的', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            url: '@Url.Action("ModifyIndexStateAsync", "Bill5")',
                            type: "post",
                            dataType: "json",
                            data: { ID: data.ID, State: 3 },
                            success: function (obj) {
                                //Info,Success,Warning,Error
                                var type = obj.Type;
                                if (type == 1) {
                                    layer.msg(obj.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            RefreshTable();
                                        });
                                } else {
                                    layer.msg(obj.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    }, function () {
                        return;
                    });
                } else if (obj.event === 'details') {
                    miniTab.openNewTabByIframe({
                        href: '@Url.Action("DetailsList", "Bill5")' + '?ID=' + data.ID,
                        title: "流程卡详情",
                    });
                    return false;
                } else if (obj.event === 'jiaofu') {
                    miniTab.openNewTabByIframe({
                        href: '@Url.Action("JiaoFuList", "Bill5")' + '?ID=' + data.ID,
                        title: "流程卡交付详情",
                    });
                    return false;
                } else if (obj.event === 'touchan') {
                    layer.confirm('投产后不能修改流卡信息，是否继续？', {
                        btn: ['是的', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            url: '@Url.Action("ModifyIndexStateAsync", "Bill5")',
                            type: "post",
                            dataType: "json",
                            data: { ID: data.ID, State: 1 },
                            success: function (obj) {
                                //Info,Success,Warning,Error
                                var type = obj.Type;
                                if (type == 1) {
                                    layer.msg(obj.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            RefreshTable();
                                        });
                                } else {
                                    layer.msg(obj.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    }, function () {
                        return;
                    });
                } else if (obj.event === 'wancheng') {
                    layer.confirm('确认此流程卡工序全部完成？', {
                        btn: ['是的', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            url: '@Url.Action("ModifyIndexStateAsync", "Bill5")',
                            type: "post",
                            dataType: "json",
                            data: { ID: data.ID, State: 2 },
                            success: function (obj) {
                                //Info,Success,Warning,Error
                                var type = obj.Type;
                                if (type == 1) {
                                    layer.msg(obj.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            RefreshTable();
                                        });
                                } else {
                                    layer.msg(obj.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    }, function () {
                        return;
                    });
                }
            });
            function RefreshTable() {
                table.reload('table', {
                    where: {
                        Search: $('#name').val(),
                        State: $('#State').val()

                    }
                }, 'data');

            }

        });
    </script>
</body>
</html>